using System;
using System.Collections.Generic;
using System.Text;
using AllegNet;

namespace DemonHunter
{
    class BikerDemon:Entity
    {
         //walk animation index
        private static Bmp rideAnimation;
        private static Bmp attackAnimation;
        private static Bmp curAnimation;

        private DateTime start;
        private bool attacking = false;

        public BikerDemon()
        {
            entityYLoc = 480;
            entityXLoc = Logic.GetInstance().GetXLoc() - rideAnimation.Width;

            killable = true;

            curAnimation = rideAnimation;
            start = DateTime.Now;
        }

        public override void animate()
        {
            DateTime stop = DateTime.Now;
            TimeSpan elapsed = stop - start;

            // if demon is attacking, stop him if 400 milliseconds have elapsed
            if (attacking == true && elapsed.Milliseconds > 400)
            {
                attacking = false;
                curAnimation = rideAnimation;
            }

            // every second, demon has a 1/3 chance to attack
            if (elapsed.Seconds == 1)
            {
                Random rnd = new Random();

                start = stop;
                attacking = true;
                if (rnd.Next(2) == 0) Attack();
            }
        }

        public override void move()
        {
            base.move();
            // do not allow this demon to catch up with player... it should always trail behind
            if (entityXLoc + GetCurrentBitmap().Width > PlayerCharacter.GetInstance().getEntityXLoc())
                entityXLoc = PlayerCharacter.GetInstance().getEntityXLoc() - GetCurrentBitmap().Width;
        }

        private void Attack()
        {
            curAnimation = attackAnimation;

            // reduce players health, as it is impossible to avoid being hit by this demon if he attacks
            PlayerCharacter.GetInstance().ReduceHealth(3);
        }

        public new static void LoadBitmaps()
        {
            rideAnimation = Game.GetInstance().LoadBitmap("c:\\DemonHunterart\\enemy\\biker\\ride.bmp");
            attackAnimation = Game.GetInstance().LoadBitmap("c:\\DemonHunterart\\enemy\\biker\\attack.bmp");
        }

        public override Bmp GetCurrentBitmap()
        {
            return curAnimation;
        }

        public override double GetCurrentBitmapHeight()
        {
            return curAnimation.Height;
        }
    }
}
